﻿using FarmSmartSleep.Common.Domain.BeginTable;
using FarmSmartSleep.Common.Domain;
using FarmSmartSleep.Common.Dtos;
using FarmSmartSleep.Common.Infrastructure;
using MediatR;
using static FarmSmartSleep.Organ.API.Application.PromptReportCommands.PendingSelectHandler;

namespace FarmSmartSleep.Organ.API.Application.PromptReportCommands
{
    public class FirstPregnancySelectHandler : IRequestHandler<FirstPregnancySelectCommand, Result>
    {
        private readonly IBaseRepository<SleepInfor> sleepinforRep;
        private readonly IBaseRepository<Cottages> cottagesRep;
        private readonly IBaseRepository<Fields> fieldsRep;

        public FirstPregnancySelectHandler(IBaseRepository<SleepInfor> sleepinforRep, IBaseRepository<Cottages> cottagesRep, IBaseRepository<Fields> fieldsRep)
        {
            this.sleepinforRep = sleepinforRep;
            this.cottagesRep = cottagesRep;
            this.fieldsRep = fieldsRep;
        }


        /// <summary>
        /// 首次妊检提示
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<Result> Handle(FirstPregnancySelectCommand request, CancellationToken cancellationToken)
        {
            var quest = new Result() { Code = (int)CodeEnum.success };

            var list= (from a in sleepinforRep.GetAll()
                       join b in cottagesRep.GetAll() on a.RecordcottageId equals b.CottagesId
                       join c in fieldsRep.GetAll() on a.FieIdId equals c.FieIdId
                       select new PendingDTO()
                       {
                           SleepInforId = a.SleepInforId,
                           MoEarNumber = a.MoEarNumber,
                           CottagesId = b.CottagesId,
                           CottageName = b.CottageName,
                           FieIdId = c.FieIdId,
                           FieIdName = c.FieIdName,
                           SleepEntryDate = a.SleepEntryDate,
                       });

            quest.Code = (int)CodeEnum.success;
            quest.Data = list;

            return quest;
        }
    }
}
